package com.sqkj.service;

import com.sqkj.dao.ArticleStarDao;
import com.sqkj.entity.ArticleStar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ArticleStarService {
    @Resource
    ArticleStarDao dao;
    @Transactional
    public Boolean addStar(ArticleStar star) {
        if (dao.addStar(star) > 0) {
            return true;
        } else {
            return false;
        }
    }
    @Transactional
    public Boolean removeStar(int userId, int articleId) {
        if (dao.removeStar(userId,articleId)> 0) {
            return true;
        } else {
            return false;
        }
    }
    @Transactional
    public Boolean giveStar(int userId, int articleId) {
        if (dao.giveStar(userId, articleId) > 0) {
            return true;
        } else {
            return false;
        }
    }

    public Boolean findByUserIdAndArticleId(int userId, int articleId) {
        if (dao.findByUserIdAndArticleId(userId, articleId) == null) {
            return false;
        } else {
            return true;
        }
    }

    public int findStarStatus(int userId, int articleId) {
        return dao.findStarStatus(userId, articleId);

    }

    public List<Integer> findMyselfStar(int userId) {
        return dao.findMyselfStar(userId);
    }
}
